﻿using Arim.S4.Client.Base.Dto;
using Arim.S4.Client.Service;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Arim.S4
{
    public sealed class ApplicationContext
    {
        private static readonly Lazy<ApplicationContext> lazy = new Lazy<ApplicationContext>(() => new ApplicationContext());
        private IList<MachineDto> machines = null;

        private ApplicationContext()
        {
        }

        public static ApplicationContext Instance
        {
            get
            {
                return lazy.Value;
            }
        }

        public UserDto User { get; set; }


        public T GetAppService<T>() where T : IAppService, new()
        {
            return new T();
        }

        public IList<MachineDto> Machines
        {
            get
            {
                if (this.machines == null || this.machines.Count() == 0)
                    this.machines = this.GetAppService<MachineAppService>().GetPagedList(new PageDto() { Asc = true })?.Items;
                return this.machines;
            }
        }

    }
}
